<?php
	session_start();	
?>

<?php
	if( $_SESSION["admin"] != "" )
	{
?>
<a href="index.php?com=page"><b>List page</a></b> | <b><a href="index.php?com=page&func=add">Add new page</b></a>
<br />
<?php 
	include_once("process/page.php");
	$page = new page();
    if( isset($_POST['btnAdd']) )
	{	
	   $file = $_FILES["Picture"];
		$file_name = $file["name"];
		$file_ext = explode(".",$file_name);
		if($file["name"] == "")
		{	
			$DepartmentID = stripcslashes($_POST["DepartmentID"]);
    		$Title=stripcslashes($_POST["Title"]);
    		$Link=stripcslashes($_POST["Link"]);
            $Picture=$file_name;
            $Description=stripcslashes($_POST["Description"]);
            $FeaturedYN=stripcslashes($_POST["FeaturedYN"]);
            $SortPriority=stripcslashes($_POST["SortPriority"]);
            $ActiveYN=stripcslashes($_POST["ActiveYN"]);
        //echo $code, $name, $order;
            if($Title != "")
            {
        		$page->AddPage($DepartmentID, $Title, $Link, $Picture, $Description, $FeaturedYN, $SortPriority, $ActiveYN);	
        		echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=page" />';
        		return;
            }
        }
        if($file_ext[count($file_ext)-1] == "jpg" || $file_ext[count($file_ext)-1] == "jpeg" || $file_ext[count($file_ext)-1] == "gif")
		{
		      $DepartmentID = stripcslashes($_POST["DepartmentID"]);
    		$Title=stripcslashes($_POST["Title"]);
    		$Link=stripcslashes($_POST["Link"]);
            $Picture=$file_name;
            $Description=stripcslashes($_POST["Description"]);
            $FeaturedYN=stripcslashes($_POST["FeaturedYN"]);
            $SortPriority=stripcslashes($_POST["SortPriority"]);
            $ActiveYN=stripcslashes($_POST["ActiveYN"]);
        //echo $code, $name, $order;
            if($Title != "")
            {
        		$page->AddPage($DepartmentID, $Title, $Link, $Picture, $Description, $FeaturedYN, $SortPriority, $ActiveYN);
                move_uploaded_file($_FILES["Picture"]["tmp_name"],"asset/".$_FILES["Picture"]["name"]);	
        	//	echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=page" />';
        		//return;
            }
		}
        else
		{
			$alert='<script type="text/javascript">
			alert("Bạn chỉ được phép chọn file có định dạng jpg, jpeg, gif");
			</script>';
			echo $alert;
		}
	}
?>

<form method="post" action="index.php?com=page&func=add" id="contactform" name="addcountry" onSubmit="return validateForm()" enctype="multipart/form-data">
	<table width="70%" style="font-size:10pt;">
		<tr>
			<td align="center" colspan="2" height="50"><b style="font-size:12pt; color:Blue;">Add new page</b></td>
		</tr>
		<tr height="26">
			<td align="right" width="120px">Department :&nbsp;&nbsp;
			</td>
			<td width="140px">
            <input type="text" class="validate[required]" name="DepartmentID" id="DepartmentID"/><font style="color: red;"> *</font>
			</td>
        </tr>
        <tr>
			<td align="right" width="120px">Title :&nbsp;&nbsp;</td>
			<td><input type="text" class="validate[required]" name="Title" id="Title" /><font style="color: red;"> *</font></td>
		</tr>  	    
        <tr>
			<td align="right" width="120px">Link :&nbsp;&nbsp;</td>
			<td><input type="text" class="validate[required]" name="Link" id="Link" /><font style="color: red;"> *</font></td>
		</tr> 
        <tr>
			<td align="right" width="120px">Picture :&nbsp;&nbsp;</td>
			<td><input type="file" name="Picture" id="Picture"/><font style="color: red;"> *</font></td>
		</tr>  	    
        <tr>
			<td align="right" width="120px">Description :&nbsp;&nbsp;</td>
			<td><textarea rows="7" name="Description" id="Description" cols="95"></textarea></td>
		</tr>
        <tr>
			<td align="right" width="120px">FeaturedYN :&nbsp;&nbsp;</td>
			<td>
            	<select size="1" name="FeaturedYN">
        			<option value="No">No</option>
                    <option value="Yes">Yes</option>
			 </select>
            </td>
		</tr>
        <tr>
			<td align="right" width="120px">SortPriority :&nbsp;&nbsp;</td>
			<td><input type="text" name="SortPriority" id="SortPriority" /><font style="color: red;"> *</font></td>
		</tr>
        <tr style="font-weight:bold;">
			<td align="right">ActiveYN :&nbsp;&nbsp;</td>
			<td>
				<select size="1" name="ActiveYN">
        			<option value="No">No</option>
                    <option value="Yes">Yes</option>
			 </select>
			</td>
		</tr>
		<tr>
			<td></td>
			<td colspan="2" align="left" height="40">
				<input type="submit" name="btnAdd" id="btnAdd" value="Add"  />
				<input type="reset" value="Reset" />
			</td>
		</tr>
	</table>
</form>
<i>Please fill in these fields (<font style="color: red;">*</font>)</i>
<?php
     }
   else
	{
		echo "<meta http-equiv='refresh' content='0; url=login.php' />";
	}
?>